function [data,data_trans] = generate_data_weitz(N,J,mu_x,sigma_x,mu_z,sigma_z,alpha,beta,...
                                           mu_c,sigma_c,input_list,output_list)

% draw data

x = randn(N,J)*sigma_x + mu_x;
z = randn(N,J)*sigma_z + mu_z;

c = exp(randn(N,1)*sigma_c + mu_c);
epsilon = -evrnd(0,1,[N,J]);

choice = zeros(N,1);
choice_seq = zeros(N,1);
open = zeros(N,J);

for i=1:N
       
    c_temp = c(i);
    
    % get reservation value in units of z (same for all j)
    reserve_z_temp = reserve_z_fun(c_temp,beta,sigma_z,input_list,output_list);
    
    delta_armstrong_temp = alpha*x(i,:) + beta*min(z(i,:),reserve_z_temp) + epsilon(i,:);
    
    [~,choice(i)] = max(delta_armstrong_temp,[],2);
    
    % get which boxes are opened
    delta_prior_temp = alpha*x(i,:) + epsilon(i,:);
    [~,ind_sort] = sort(delta_prior_temp,'descend');
    
    delta_full_temp = alpha*x(i,:) + beta*z(i,:) + epsilon(i,:);
    delta_prior_reserve_temp = alpha*x(i,:) + beta*reserve_z_temp + epsilon(i,:);
    
    j = 1;
    temp_search = 1;
    while j<=J-1 && temp_search==1
        
        temp_ind = ind_sort(j);
        open(i,temp_ind) = 1;
        
        temp_u_inhand = max(delta_full_temp(logical(open(i,:))));
        
        temp_search = (temp_u_inhand<delta_prior_reserve_temp(ind_sort(j+1)));
        j = j+1;
        
    end
    
    if j==J && temp_search==1
        open(i,ind_sort(J)) = 1;
    end
    
    % check
    [~,max_temp] = max(delta_full_temp(logical(open(i,:))));
    ind_temp = find(open(i,:));
    choice_seq(i) = ind_temp(max_temp);
            
end

data.x = x;
data.z = z;
data.c = c;
data.epsilon = epsilon;
data.choice = choice;
data.open = open;
% data.y = zeros(size(choice));
% data.y(choice==1) = 1;

data = struct2dataset(data);

data_trans = transform_data_01(data,J);

end

